package com.yyn.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yyn.order.entity.TOrder;
import com.yyn.order.mapper.TOrderMapper;
import com.yyn.order.service.TOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yyn.servicebase.exceptionhandler.CustomException;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author yyn
 * @since 2023-01-12
 */
@Service
public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> implements TOrderService {

    @Override
    public int checkPayCourse(String courseId, String memberId) {
        LambdaQueryWrapper<TOrder> tOrderLambdaQueryWrapper = new LambdaQueryWrapper<>();
        tOrderLambdaQueryWrapper.eq(TOrder::getCourseId,courseId);
        tOrderLambdaQueryWrapper.eq(TOrder::getMemberId,memberId);//判断用户
        TOrder pay = this.getOne(tOrderLambdaQueryWrapper);
        if(pay != null){
            Integer status = pay.getStatus();
            return status;

        }
        throw new CustomException(20001,"用户未登录");

    }

    @Override
    public TOrder getOrderInfoByNo(String orderNo) {
        LambdaQueryWrapper<TOrder> tOrderLambdaQueryWrapper = new LambdaQueryWrapper<>();
        tOrderLambdaQueryWrapper.eq(TOrder::getOrderNo,orderNo);
        TOrder tOrder = this.getOne(tOrderLambdaQueryWrapper);
        return tOrder;
    }
}
